From 07f8d1fdbf4993d8a2c475c99d9d22bd983e23fd Mon Sep 17 00:00:00 2001 From: "kfraser@localhost.localdomain" Date: Tue, 15 May 2007 10:50:09 +0100 Subject: [PATCH] Fix TPM support in HVM domains Signed-off-by: Joseph Cihula Signed-off-by: Peter Yang --- tools/examples/vtpm-impl | 2 +- tools/ioemu/hw/tpm_tis.c | 25 ++++++++++++++++++++----- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/tools/examples/vtpm-impl b/tools/examples/vtpm-impl index 148e9dc187..4f9a1fd85e 100644 --- a/tools/examples/vtpm-impl +++ b/tools/examples/vtpm-impl @@ -83,7 +83,7 @@ function vtpm_manager_cmd() { release_lock vtpm_mgr #return whether the command was successful - if [ $resp_hex ne $TPM_SUCCESS ]; then + if [ $resp_hex -ne $TPM_SUCCESS ]; then vtpm_fatal_error=1 false else diff --git a/tools/ioemu/hw/tpm_tis.c b/tools/ioemu/hw/tpm_tis.c index 29bb14c942..39309809ad 100644 --- a/tools/ioemu/hw/tpm_tis.c +++ b/tools/ioemu/hw/tpm_tis.c @@ -148,7 +148,7 @@ static int write_local_socket(tpmState *s, const tpmBuffer *); static int read_local_socket(tpmState *s, tpmBuffer *); static int close_local_socket(tpmState *s, int force); static int has_channel_local_socket(tpmState *s); -#define LOCAL_SOCKET_PATH "/var/vtpm/vtpm_all.socket" +#define LOCAL_SOCKET_PATH "/var/vtpm/socks/%d.socket" #define NUM_TRANSPORTS 1 @@ -238,18 +238,33 @@ static int create_local_socket(tpmState *s, uint32_t vtpm_instance) if (s->tpmTx.fd[0] < 0) { s->tpmTx.fd[0] = socket(PF_LOCAL, SOCK_STREAM, 0); +#ifdef DEBUG_TPM + fprintf(logfile," SOCKET FD %d errno %d \n", s->tpmTx.fd[0], errno ); +#endif if (has_channel_local_socket(s)) { + int ret; struct sockaddr_un addr; memset(&addr, 0x0, sizeof(addr)); addr.sun_family = AF_LOCAL; - strcpy(addr.sun_path, LOCAL_SOCKET_PATH); - if (connect(s->tpmTx.fd[0], - (struct sockaddr *)&addr, - sizeof(addr)) != 0) { + snprintf(addr.sun_path, sizeof(addr.sun_path)-1, + LOCAL_SOCKET_PATH, (uint32_t) vtpm_instance); +#ifdef DEBUG_TPM + fprintf(logfile," SOCKET NAME %s \n", addr.sun_path ); +#endif + + if ((ret = connect(s->tpmTx.fd[0], (struct sockaddr *)&addr, + sizeof(addr))) != 0) { close_local_socket(s, 1); +#ifdef DEBUG_TPM + fprintf(logfile," RET %d errno %d\n", ret, errno ); +#endif success = 0; } else { /* put filedescriptor in non-blocking mode for polling */ +#ifdef DEBUG_TPM + fprintf(logfile," put filedescriptor in non-blocking mode " + "for polling \n"); +#endif int flags = fcntl(s->tpmTx.fd[0], F_GETFL); fcntl(s->tpmTx.fd[0], F_SETFL, flags | O_NONBLOCK); } -- 2.30.2